#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ == taoyulong2018@gmail.com
# __time__ == 2023/8/29 16:49
# ===========================================
#       题目名称： 48. 旋转图像
#       题目地址： https://leetcode.cn/problems/rotate-image/description/
#       题目描述： https://note.youdao.com/s/RRXNSXjR
# ===========================================
from typing import List, Tuple, Dict, Set


class Solution:
    def rotate(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        stack = []  # 定义一个列表用来存matrix 中的数据
        for i in range(len(matrix)):
            for j in range(len(matrix[i])):
                stack.insert(0, matrix[i][j])
        i, j = 0, len(matrix) - 1
        while j > -1:
            element = stack.pop()
            matrix[i][j] = element
            if i + 1 > len(matrix) - 1:
                j -= 1
                i = 0
            else:
                i += 1
        # print(matrix)


if __name__ == '__main__':
    s = Solution()
    # [[7,4,1],[8,5,2],[9,6,3]]
    s.rotate(matrix=[[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    # [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
    s.rotate(matrix=[[5, 1, 9, 11], [2, 4, 8, 10], [13, 3, 6, 7], [15, 14, 12, 16]])
